<?php
namespace app\admin\validate;

use think\Validate;

class Product extends Validate {

    protected $rule = [
        "title" => "require",
        "category_path_id" => "require",
        "category_id" => "require",
        "sub_title" => "require",
        "sku" => "require",
        "promotion_title" => "require",
        "is_show_stock" => "require|between:0,1",
        "spec_type" => "require|between:1,2|checkSpecsType",
        "carousel_img" => "require",
        "recommend_img" => "require",
        "description" => "require",
//        "skus" => "checkSkus",
//        "add_spec_arr" => "checkAddSpecArr",
    ];

    protected $message = [
        "title.require" => "产品标题不能为空",
        "category_path_id.require" => "分类目录获取失败",
        "category_id.require" => "分类获取失败",
        "sub_title.require" => "产品副标题不能为空",
        "sku.require" => "产品SKU不能为空",
        "promotion_title.require" => "推广语不能为空",
        "is_show_stock.require" => "是否显示库存获取参数失败",
        "specs_type.require" => "规格类型获取失败",
        "is_show_stock.between" => "是否显示库存获取参数失败",
        "specs_type.between" => "规格类型获取失败",
        "carousel_img.require" => "产品详情页的轮番图不能为空",
        "recommend_img.require" => "产品推荐图不能为空",
        "description.require" => "产品描述不能为空",
    ];

    public function checkSpecsType($value, $rule, $data) {
        if ($value != "2") {
            return true;
        }
        if (empty($data["skus"])) {
            return "skus获取失败";
        }
        if (empty($data["add_spec_arr"])) {
            return "规格获取失败";
        }

        return true;
    }


}